<script setup lang="ts">
import { onMounted, ref } from 'vue';
import Top from './components/top/index.vue';
import Tourist from './components/tourist/index.vue';
import Map from './components/map/index.vue';
import Rank from './components/rank/index.vue';

const screen = ref();
// 定义大屏缩放比例
function getScale(w = 1920, h = 1080) {
  const ww = window.innerWidth / w;
  const wh = window.innerHeight / h;
  return ww < wh ? ww : wh;
}
window.onresize = () => {
  screen.value.style.transform = `scale(${getScale()}) translate(-50%,-50%)`;
};

// 根据地图数据更新右边数据
const company: any = {
  越城区: '中国电信股份有限公司绍兴分公司(本部)',
  柯桥区: '中国电信股份有限公司柯桥分公司',
  上虞区: '中国电信股份有限公司上虞分公司',
  诸暨市: '中国电信股份有限公司诸暨分公司',
  嵊州市: '中国电信股份有限公司嵊州分公司',
  新昌县: '中国电信股份有限公司新昌分公司',
};
const mName = ref<string>('绍兴市');
const companys = ref<string>('');
function handleMName(newData: string) {
  mName.value = newData;
  companys.value = company[mName.value];
}
// 监听mName的变化更改companys
watch(mName, () => {
  getCompanyByM();
});
function getCompanyByM() {
  if (mName.value === '绍兴市') {
    companys.value = '';
  }
  else {
    companys.value = company[mName.value];
  }
}
provide('mName', mName);
provide('companys', companys);

onMounted(() => {
  screen.value.style.transform = `scale(${getScale()}) translate(-50%,-50%)`;
});
</script>

<template>
  <div class="screen-container">
    <div ref="screen" class="screen">
      <div class="top">
        <Top />
      </div>
      <div class="bottom">
        <div class="left">
          <Map class="map" @m-name="handleMName" />
        </div>
        <div class="right">
          <Tourist class="tourist" />
          <Rank class="rank" />
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.screen-container {
  width: 100vw;
  height: 100vh;
  background: url(./images/bg.png) no-repeat;
  background-size: cover;

  .screen {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 1920px;
    height: 1080px;
    transform-origin: left top;

    .top {
      width: 100%;
      height: 40px;
    }

    .bottom {
      display: flex;

      .right {
        display: flex;
        flex: 1;
        flex-direction: column;
        margin-bottom: 40px;
        margin-left: 40px;

        .tourist {
          flex: 1;
        }

        .rank {
          flex: 1;
        }
      }

      .left {
        display: flex;
        flex: 2;
        flex-direction: column;
        height: 1040px;
        margin-top: 30px;

        .map {
          flex: 1;
        }
      }
    }
  }
}
</style>
